512b0ef6bfdbb9cf31c3b2577b50c4b2eaeb0388,hazelcast/src/test/java/com/hazelcast/map/SizeEstimatorTest.java,SizeEstimatorTest,testPutRemove,#,63
Before Change
final IMap<String, String> map = h[0].getMap(MAP_NAME);
map.put("key", "value");
long h1MapCost = h[0].getMap(MAP_NAME).getLocalMapStats().getHeapCost();
long h2MapCost = h[1].getMap(MAP_NAME).getLocalMapStats().getHeapCost();
Assert.assertTrue(h1MapCost > 0);
Assert.assertTrue(h2MapCost > 0);
// one map is backup. so backup & main map cost must be same.
Assert.assertEquals(h1MapCost, h2MapCost);
map.remove("key");
h1MapCost = h[0].getMap(MAP_NAME).getLocalMapStats().getHeapCost();
h2MapCost = h[1].getMap(MAP_NAME).getLocalMapStats().getHeapCost();
Assert.assertEquals(0, h1MapCost);
Assert.assertEquals(0, h2MapCost);
After Change
@Test
public void testPutRemoveWithTwoNodeOwnerAndBackup() throws InterruptedException {
final String mapName = "default";
final Config config = new Config();
config.getMapConfig(mapName).setBackupCount(1).setInMemoryFormat(InMemoryFormat.BINARY);
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h[] = factory.newInstances(config);
warmUpPartitions(h);
//create map
final IMap<String, String> map1 = h[0].getMap(mapName);
final IMap<String, String> map2 = h[1].getMap(mapName);
//calculate initial heap costs.
long map1Cost = map1.getLocalMapStats().getHeapCost();
long map2Cost = map2.getLocalMapStats().getHeapCost();
//check initial costs if zero.
assertEquals("map1 initial heap cost must be zero..." + map1Cost, 0, map1Cost);
assertEquals("map2 initial heap cost must be zero..." + map2Cost, 0, map2Cost);
//populate map
map1.put("key", "value");
//get sizes
long map1Size = map1.size();
long map2Size = map2.size();
//check sizes
assertEquals("map1 size must be one..." + map1Size, 1, map1Size);
assertEquals("map2 size must be one..." + map2Size, 1, map2Size);
//calculate costs
map1Cost = map1.getLocalMapStats().getHeapCost();
map2Cost = map2.getLocalMapStats().getHeapCost();
//costs should not be zero.
assertTrue("map1 cost should be greater than zero....: " + map1Cost, map1Cost > 0);
assertTrue("map2 cost should be greater than zero.... : " + map2Cost, map2Cost > 0);
// one map is backup. so backup & owner cost must be same.
assertEquals(map1Cost, map2Cost);
//remove key.
map1.remove("key");
//get sizes
map1Size = map1.size();
map2Size = map2.size();
//check if sizes zero.
assertEquals("map1 size must be zero..." + map1Size, 0, map1Size);
assertEquals("map2 size must be zero..." + map2Size, 0, map2Size);
map1Cost = map1.getLocalMapStats().getHeapCost();
map2Cost = map2.getLocalMapStats().getHeapCost();
//costs should be zero.
assertTrue("map1 cost should zero....: " + map1Cost, map1Cost == 0);
assertTrue("map2 cost should zero....: " + map2Cost, map2Cost == 0);